package com.qdu.servlet;

import com.qdu.entity.Log;
import com.qdu.entity.LogRemark;
import com.qdu.entity.LogResponse;
import com.qdu.service.impl.LogRemarkServiceImpl;
import com.qdu.service.impl.LogResponseServiceImpl;
import com.qdu.service.impl.LogServiceImpl;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 从主页面点击查看一个日志
 *
 * @author Lenovo
 */
@WebServlet("/mainsols")
public class MainSearchOneLogServlet extends HttpServlet{

    LogServiceImpl logserviceimpl=new LogServiceImpl();
    LogRemarkServiceImpl logremarkserviceimpl=new LogRemarkServiceImpl();
    LogResponseServiceImpl logresponseserviceimpl=new LogResponseServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        
        //获取请求参数
        String logID=req.getParameter("id");//获取日志编号
        
        //执行业务逻辑
        Log log=logserviceimpl.getOneLogById(logID);//根据日志名称查询该日志，然后将该日志添加到请求参数中
        List<Log> list=logserviceimpl.getAllLog();//查找所有日志，以便于在右面显示更多日志名称
        List<LogRemark> remarks=logremarkserviceimpl.getAllRemark(logID);//查找日志的评论
        List<LogResponse> response=logresponseserviceimpl.getAllResponse();//查找评论的回复
        
        //生成相应内容
        req.setAttribute("log", log);
        req.setAttribute("list",list);
        req.setAttribute("remarks", remarks);
        req.setAttribute("response", response);
        req.getRequestDispatcher("/mainOneLog.jsp").forward(req, resp);
//        publishLog.jsp
    }
}
